package com.xiaoma.controller;

import com.xiaoma.component.AliOssCompent;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import utils.R;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.Map;

/**
 * @description:
 * @Author: xiaoma
 * @Date: 2021/8/27 16:19
 */
@RestController
@RequestMapping("/aliOss")
@Slf4j
public class AliOssController {
    @Autowired
    private AliOssCompent aliOssCompent;

    @RequestMapping("/policy")
    public Map<String, String> policy(){
      return aliOssCompent.policy();
    }
    @RequestMapping("/upload")
    public boolean upload(@RequestBody File file){
        return aliOssCompent.upload2OssByFile("C:\\Users\\93635\\Desktop\\"+file.getName(),file.getName());
    }
    //document.location.href = data.content;
    @RequestMapping("/download")
    public String download(HttpServletRequest request){
        return aliOssCompent.getOssDownloadUrl("redis.docx", "123.docx", request);
    }
}
